<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script language="javascript">
var isCorrect = true;
var needFocus;
	$().ready( function() {
		$('#startDate').datepick({minDate:new Date(<%=request.getAttribute("minDate").toString()%>), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$('#endDate').datepick({minDate:new Date(<%=request.getAttribute("minDate").toString()%>), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$("#limitPrice").numeric({allow:"."});
		$("#productId").numeric();
		if('${productId}'!=''){
			checkShelf('${productId}');
		}
		$("#productId").blur(function(){
			$("#prodIsOk").val('N');
			$("#productId").val(prodPadLeft($("#productId").val()));
			getProductInfo3("${midContextPath}","productName",null,"prodIsOk",$("#productId").val());
			checkShelf($("#productId").val());
		});
		$('#submit_button').click(function(){
			isCorrect = true;
			$("span:[id*=Tip]").hide();
			$("span:[id*=Tip]").text('');

			if($("#startDate").val()==''){
				$("#startDateTip").text('请选择起始日期');
				$("#startDateTip").show();
				needFocus = $("#startDate");
				isCorrect = false;
			}

			if($("#endDate").val()==''){
				$("#endDateTip").text('请选择起始日期');
				$("#endDateTip").show();
				needFocus = $("#endDate");
				isCorrect = false;
			}

			if($("#productId").val()==''){
				$("#productIdTip").text('请输入商品编号');
				$("#productIdTip").show();
				needFocus=$("#productId");
				isCorrect = false;
			}else if($("#prodIsOk").val()=='N'){
				$("#productIdTip").text('请输入正确的商品编号');
				$("#productIdTip").show();
				needFocus=$("#productId");
				isCorrect = false;
			}

			if($("#productName").val()==''){
				$("#productNameTip").text('请输入商品名称');
				$("#productNameTip").show();
				needFocus=$("#productName");
				isCorrect = false;
			}else if($("#productName").val().length>40){
				$("#productNameTip").text('商品名称超出40');
				$("#productNameTip").show();
				needFocus=$("#productName");
				isCorrect = false;
			}

			if($("#limitPrice").val()==''){
				$("#limitPriceTip").text('请输入秒杀价');
				$("#limitPriceTip").show();
				needFocus=$("#limitPrice");
				isCorrect = false;
			}
			
			if(isCorrect){
				$('#prodLimitSaleForm').submit();
			}else{
				needFocus.focus();
			}
		}); 
	});

function checkShelf(productId){
	$.post('${midContextPath}/productLimitSale/findProductShelf.do',{'productId':productId,'startDate':$("#startDate").val()+' '+$("#startTime").val(),'endDate':$("#endDate").val()+' '+$("#endTime").val()},checkShelfCallback,"json");
}
function checkShelfCallback(result){
	if(result=='timeError'){
		$("#endDateTip").text('请输入正确起迄时间');
		$("#endDateTip").show();
		$("#shelfChecked").val('N');
		return;
	}
	$("#endDateTip").hide();
	$("#shelfMsg > td").html(result);
	$("#shelfMsg").show();
}
</script>
<div style="color:red">
<s:actionerror/>
<s:actionmessage/>
<s:fielderror />
</div>
<h1>商品限购管理
<span class="f-link"><a href="${midContextPath}/productLimitSale/search.do">回列表页</a></span></h1>
<font color='red'>每笔资料为一个活动，每一个活动区间，每个会员只能购买一次</font>
<s:form action="save.do" method="post" name="prodLimitSaleForm" id="prodLimitSaleForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>#</th>
				<td>${id}<input type="hidden" name="id" value="${id}"/></td>
			</tr>
			<tr>
				<th>起始时间</th>
				<td>
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/>
				<select id="startTime" name="startTime">			
						<c-rt:forEach begin="0" end="23" var="t1">
							<c-rt:if test="${t1<10}">
							<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<c-rt:if test="${t1>=10}">
							<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
						</c-rt:forEach>
				</select>  
				<span id="startDateTip" class="msg rn" style="display:none;"></span><span id="startTimeTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>结束时间</th>
				<td> 
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select>
				<span id="endDateTip" class="msg rn" style="display:none;"></span><span id="endTimeTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品编号</th>
				<td><input type="text" name="productId" id="productId" maxlength="8" size="10" value="${productId}" />
				<br/><span id="productIdTip" class="msg rn" style="display:none;"></span>
				<input type="hidden" id="prodIsOk" value=""/>
				</td>
			</tr>
			<tr>
				<th>商品名称</th>
				<td><input type="text" id="productName" name="productName" value="${productName}" size="60" maxlength="40"/><br/><span id="productNameTip" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr>
				<th>秒杀价</th>
				<td><input type="text" name="limitPrice" id="limitPrice" value="${limitPrice}" maxlength="10" size="10" />
				<br/><span id="limitPriceTip" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr id="shelfMsg" style="display:none;">
				<th>商品资讯</th>
				<td></td>
			</tr>
		</tbody>
	</table>
	<input type="button" id="submit_button" value="储存"/>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/productLimitSale/search.do">回列表页</a>
</div>